package gsb.gsb;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import java.util.List;
import modele.DAO;

public class MainActivity extends ListActivity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final ListView listView = getListView();
        final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) listView.getLayoutParams();
        params.gravity = Gravity.CENTER_HORIZONTAL;
        listView.setLayoutParams(params);
        // lecture des noms
        List<String> lesDeps = DAO.getLesDeps();
        // Création de l'adapter
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, lesDeps);
        setListAdapter(adapter);
    }
    
    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        Intent inter = new Intent(this, AutreActivity.class);
        String leDep = getListAdapter().getItem(position).toString();
        inter.putExtra("leDep", l.getItemAtPosition(position).toString());
        startActivity(inter);
    }
}
